<?php
/**
 * @package Autogenerator for Joomla!
 * @version 3.0.0
 * @author Truong Cong Duc <truongcongduc4@gmail.com>
 * @link autogenerator.blogspot.com
 * @copyright (c) 2013, Truong Cong Duc
 * @license GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

JFormHelper::loadFieldClass('list');

class JFormFieldLib extends JFormFieldList
{

    public $type = 'Lib';

    protected function getOptions()
    {
        $options = array();

        $db = JFactory::getDbo();
        $query = $db->getQuery(true);

        $query->select('lib.id AS value, lib.title AS text');
        $query->from('#__auto_lib AS lib');
        $query->order('lib.ordering DESC');

        $db->setQuery($query);

        try
        {
            $options = $db->loadObjectList();
        }
        catch (RuntimeException $e)
        {
            JError::raiseWarning(500, $e->getMessage);
        }
        
        $parent = new stdClass;
        $parent->text = JText::_('JGLOBAL_ROOT_PARENT');
        $parent->value = '';
        array_unshift($options, $parent);

        return $options;
    }

}
